package mycine.controller.actions;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import mycine.model.beans.Usermc;
import mycine.model.dao.UsermcDAO;

/**
 *
 * @author Vincent
 */
public class UsermcAction extends ActionSupport {
	
	private Usermc usermc;
	private boolean keepConnect;
	
	public Usermc getUsermc() {
		return usermc;
	}

	public void setUsermc(Usermc usermc) {
		this.usermc = usermc;
	}

	public boolean isKeepConnect() {
		return keepConnect;
	}

	public void setKeepConnect(boolean keepConnect) {
		this.keepConnect = keepConnect;
	}
	
	public String login() {
		UsermcDAO userDAO = new UsermcDAO();
		String emailForm = usermc.getEmail();
		String passwordForm = usermc.getPassword();
		
		Usermc loginUser = userDAO.login(emailForm, passwordForm);

		if (loginUser != null) {
			Map<String, Object> session = ActionContext.getContext().getSession();
			session.put("authentification", "true");
			session.put("lastName", loginUser.getLastName());
			session.put("firstName", loginUser.getFirstName());

			return SUCCESS;
		}
		
		return ERROR;
	}
	
	public String forgetPassword() {
		return SUCCESS;
	}
	
	public String signOn() {
		return SUCCESS;
	}
	
	public String disconnect() {
		return SUCCESS;
	}
	
}
